package com.mall.service.ps;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.mall.client.ps.PsService;
import com.mall.custom.dao.read.PsCodeReadMapper;
import com.mall.custom.dao.read.PsItemReadMapper;
import com.mall.custom.dao.write.PsCodeWriteMapper;
import com.mall.custom.dao.write.PsItemWriteMapper;
import com.mall.pojo.PsCode;
import com.mall.pojo.PsCodeExample;
import com.mall.pojo.PsCodeExample.Criteria;
import com.mall.pojo.PsItem;
import com.mall.pojo.PsItemExample;
@Service
public class PsServiceImpl implements PsService {
	@Autowired
	private PsCodeReadMapper psCodeReadMapper;
	@Autowired
	private PsCodeWriteMapper psCodeWriteMapper;
	
	@Autowired
	private PsItemReadMapper psItemReadMapper;
	@Autowired
	private PsItemWriteMapper  psItemWriteMapper;
	@Override
	public PsCode getPsCodeByCode(String code) {
		PsCodeExample example = new PsCodeExample();
		Criteria criteria = example.createCriteria();
		criteria.andCodeEqualTo(code);
		criteria.andStatusEqualTo("使用");
		List<PsCode> psCodeList = this.psCodeReadMapper.selectByExample(example);
		PsCode psCode =null;
		if(psCodeList != null && psCodeList.size()>0){
			psCode = psCodeList.get(0);
		}
		return psCode;
	}
	
	@Override
	public int insertPsCode(PsCode psCode) {
		return this.psCodeWriteMapper.insert(psCode);
		
	}

	@Override
	public PsItem getPsItemByCode(String psItemCode) {
		PsItemExample example = new PsItemExample();
		com.mall.pojo.PsItemExample.Criteria criteria = example.createCriteria();
		criteria.andCodeEqualTo(psItemCode);
		List<PsItem> psItemList = this.psItemReadMapper.selectByExample(example);
		PsItem psItem = null;
		if(psItemList != null && psItemList.size()>0){
			psItem = psItemList.get(0);
		}
		return psItem;
	}

	@Override
	public PsItem getPsItemById(Integer psItemId) {
		return this.psItemReadMapper.selectByPrimaryKey(psItemId);
	}

	@Override
	public List<PsItem> getPsItemListByExample(PsItemExample example) {
		return this.psItemReadMapper.selectByExample(example);
	}

	@Override
	public int modifyPsItem(PsItem psItem) {
		return this.psItemWriteMapper.updateByPrimaryKey(psItem);
		
		
	}

	@Override
	public Integer getPsItemCountByExample(PsItemExample example) {
		return this.psItemReadMapper.countByExample(example);
	}

	@Override
	public Integer insertPsItem(PsItem psItem) {
		return this.psItemWriteMapper.insert(psItem);
	}

}
